package com.ycky.connect.websocket;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @description: websocket管理类
 * @author: cjj
 * @time: 2025/3/18 16:54
 */

@Slf4j
public class WebSocketManager {
    //存储所有的websocket连接与uid映射关系
    private static final ConcurrentHashMap<String, WebSocketServer> WEB_SOCKET_MAP = new ConcurrentHashMap<>();


    /**
     * @description: 添加websocket连接
     * @author: cjj
     * @date: 2025/3/18 17:08
     * @param: [webSocketServer]
     **/
    public static void addWebSocketServer(WebSocketServer webSocketServer) {
        WEB_SOCKET_MAP.put(webSocketServer.getUid(), webSocketServer);
    }

    /**
     * @description: 移除websocket连接
     * @author: cjj
     * @date: 2025/3/18 17:09
     * @param: [webSocketServer]
     **/
    public static void removeWebSocketServer(WebSocketServer webSocketServer) {
        WEB_SOCKET_MAP.remove(webSocketServer.getUid());
    }

    /**
     * @description: 通过uid发送消息给特定用户
     * @author: cjj
     * @date: 2025/3/18 17:11
     * @param: [sessionId, msg]
     **/
    public static void sendMsgToUser(String uid, String msg) {

    }

    /**
     * @description: 群发消息
     * @author: cjj
     * @date: 2025/3/18 17:11
     * @param: [session, msg]
     **/
    public static void sendMsgToAll(String msg) {

    }

}